package com.sanjiahantang.youjiarole.module.common.models.impl;

import android.content.Context;

import com.sanjiahantang.youjiarole.base.BaseBean;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.http.BaseDelegate;
import com.sanjiahantang.youjiarole.http.OkHttpClientManager;
import com.sanjiahantang.youjiarole.module.common.beans.FileBean;
import com.sanjiahantang.youjiarole.module.common.models.IFileModel;
import com.squareup.okhttp.Request;

import java.util.Map;

/**
 * Created by zy on 2017/10/23.
 */

public class FileModel implements IFileModel {
    public void doUpoad(final Context context, Map<String, String> param, final CallBack<FileBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/file/user/upload/uploadPhoneForRoleBase64",
                param,new BaseDelegate.ResultCallback<FileBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(FileBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }

    @Override
    public void deleteFileRole(final Context context, Map<String, String> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/file/user/upload/deleleFileRole",
                param,new BaseDelegate.ResultCallback<BaseBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(BaseBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }

    @Override
    public void uploadMallFile(final Context context, Map<String, String> param, final CallBack<FileBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/file/mall/upload/uploadPhoneForRoleBase64",
                param,new BaseDelegate.ResultCallback<FileBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(FileBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }

    @Override
    public void deleteMallFile(final Context context, Map<String, String> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/file/mall/upload/deleleFileRole",
                param,new BaseDelegate.ResultCallback<FileBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(FileBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }

    @Override
    public void uploadPlanFile(final Context context, Map<String, String> param, final CallBack<FileBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/file/plan/upload/uploadPhoneForRoleBase64",
                param,new BaseDelegate.ResultCallback<FileBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(FileBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }

    @Override
    public void deletePlanFile(final Context context, Map<String, String> param, final CallBack<BaseBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/file/plan/upload/deleleFileRole",
                param,new BaseDelegate.ResultCallback<FileBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(FileBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }

    @Override
    public void searchFieldList(final Context context, Map<String, String> param, final CallBack<FileBean> callBack) {
        OkHttpClientManager.postAsyn(context, ConfigValue.API_URL + "/file/plan/upload/searchFieldList",
                param,new BaseDelegate.ResultCallback<FileBean>() {

                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        callBack.onFailure(e.getMessage());
                    }

                    @Override
                    public void onResponse(FileBean response, Object tag) {
                        callBack.onSuccess(response,context, tag);
                    }
                });
    }
}
